package com.eureka.eurekaserviceinvoker.interceptor;


import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * 自定义请求类
 */
public class MyHttpRequest implements HttpRequest {


    private HttpRequest sourceRequest;


    public MyHttpRequest(HttpRequest sourceRequest){
        this.sourceRequest = sourceRequest;
    }

    @Override
    public String getMethodValue() {
        return sourceRequest.getMethodValue();
    }

    @Override
    public URI getURI() {
        String oldURI = sourceRequest.getURI().toString();
        URI newURI = null;
        try {
            newURI = new URI("http://localhost:8090/myLoadBalancer/hello");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        //返回被替换后的连接
        return newURI;
    }

    @Override
    public HttpHeaders getHeaders() {
        return sourceRequest.getHeaders();
    }
}
